package cn.jekun.web.agent.action;

import java.sql.Types;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.xmlbeans.impl.jam.mutable.MPackage;
import org.aspectj.weaver.patterns.ThisOrTargetAnnotationPointcut;

import com.opensymphony.xwork2.ActionContext;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import cn.jekun.component.base.bean.ErrorMsg;
import cn.jekun.component.base.exceptions.BusinessException;
import cn.jekun.component.base.exceptions.TimeoutException;
import cn.jekun.component.base.utils.SqlUtis;
import cn.jekun.component.core.Constants;
import cn.jekun.component.core.bean.RandomValidateCode;
import cn.jekun.component.core.bean.gen.ErpShop;
import cn.jekun.component.core.bean.gen.RsAgent;
import cn.jekun.component.core.bean.gen.RsAuth;
import cn.jekun.component.core.bean.gen.RsUser;
import cn.jekun.component.core.service.CoreAuthService;
import cn.jekun.component.core.service.gen.RsUserService;
import cn.jekun.web.agent.bean.Agent;
import cn.jekun.web.agent.bean.ShopMemberConcern;
import cn.jekun.web.agent.service.WebAgentService;
import cn.jekun.web.shop.action.ShopBaseAction;
import cn.jekun.web.shop.bean.UserLogin;
import cn.jekun.web.shop.bean.WebUser;
import cn.jekun.web.shop.service.LoginService;

/**
 * 代理商登录、退出系统 
 * @author yuan
 *
 */
@SuppressWarnings("serial")
public class LoginAction extends ShopBaseAction {

	@Resource(name=RsUserService.BEAN_NAME)
	RsUserService userService;
	@Resource(name=LoginService.BEAN_NAME)
	LoginService loginService;
	
	@Resource(name=CoreAuthService.BEAN_NAME)
	protected CoreAuthService coreAuthService;
	
	@Resource(name=WebAgentService.BEAN_NAME)
	WebAgentService webAgentService;
	
	//日志记录
	Logger logger  = Logger.getLogger(LoginAction.class); 

	private String agentName;
	private String agentPassword;
	public String getAgentName() {
		return agentName;
	}

	public void setAgentName(String agentName) {
		this.agentName = agentName;
	}

	public String getAgentPassword() {
		return agentPassword;
	}

	public void setAgentPassword(String agentPassword) {
		this.agentPassword = agentPassword;
	}
	private String loginCount;
	private String logintype;
	public String getLogintype() {
		return logintype;
	}

	public void setLogintype(String logintype) {
		this.logintype = logintype;
	}

	public String getLoginCount() {
		return loginCount;
	}

	public void setLoginCount(String loginCount) {
		this.loginCount = loginCount;
	}

	@Override
	protected void validateTimeout() throws TimeoutException {
		//不需要登录
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public String Login(){
		JSONObject jsonObject = new JSONObject();
		
		
//		String imgcode = this.request.getParameter("imgcode");//用户输入的图片验证码
//		
//		ActionContext ctx = ActionContext.getContext();
//		String randomcodekey = (String) ctx.getSession().get(RandomValidateCode.RANDOMIMAGEKEY);//获取session的图片验证码
//
//		if(!(randomcodekey!=null && randomcodekey.trim().toLowerCase().equals(imgcode.trim().toLowerCase()))){
//			
//			LOG.info("验证图片验证码失败。 ip "+this.getIp() +" 浏览器 "+this.getBrowser());
//			
//			jsonObject.put(ErrorMsg.KEY_CODE, ErrorMsg.CALL_FAIL);
//			
//			jsonObject.put(ErrorMsg.KEY_MESSAGE,"验证图片验证码失败");
//			
//			return this.writeJson(jsonObject);
//		}
		
		
		
		WebUser webUser = new WebUser();
		//查找用户
//		formMap.put(RsUser.COL_USER_NAME, agentName);
//		SqlUtis.prepareSql(formMap
//				, SqlUtis.getSQL(formMap,"a."+RsUser.COL_USER_NAME,Types.VARCHAR,SqlUtis.EQ)
//				);
		RsUser user = this.loginService.one(agentName);
		if (user==null) {//手机号码
			formMap.put(RsUser.COL_MOBILE, agentName);
			SqlUtis.prepareSql(formMap
					, SqlUtis.getSQL(formMap,"a."+RsUser.COL_MOBILE,Types.VARCHAR,SqlUtis.EQ)
					);
			user = this.userService.one(this.formMap);
		}
		if(user==null){
			jsonObject.put(ErrorMsg.KEY_CODE, ErrorMsg.CALL_FAIL);
			
			jsonObject.put(ErrorMsg.KEY_MESSAGE, "用户不存在");
			
			return this.writeJson(jsonObject);
		}
//		System.out.println(agentPassword);
		//检查密码
		if(!agentPassword.equals(user.getPassword())){
			jsonObject.put(ErrorMsg.KEY_CODE, ErrorMsg.CALL_FAIL);
			
			jsonObject.put(ErrorMsg.KEY_MESSAGE, "用户名或密码不正确");
			
			return this.writeJson(jsonObject);
		}
		
		//检查是否启用
//		if(user.getStatus()!=null && user.getStatus().equals("0")){
//			
//			jsonObject.put(ErrorMsg.KEY_CODE, ErrorMsg.CALL_FAIL);
//			
//			jsonObject.put(ErrorMsg.KEY_MESSAGE, "该账户已经停用");
//			
//			return this.writeJson(jsonObject);
//		}
		
//		Map map = new HashMap();
//		map.put("userName", agentName);
//		map.put("userId", user.getUserId());
		UserLogin userLogin = this.loginService.one("ACTION_RS_USER_LOGIN.queryagentlogin",agentName,user.getUserId());
		//TODO 检查是否有代理商用户
		List<Agent> list = this.loginService.getAgentList("ACTION_RS_USER_LOGIN.agentlist", agentName,user.getUserId());
		if(list==null || list.isEmpty()){
			this.saveActionError("该用户不是代理商");
			jsonObject.put(ErrorMsg.KEY_CODE, "0");
			jsonObject.put(ErrorMsg.KEY_MESSAGE, "该用户不是代理商");
			return this.writeJson(jsonObject);
		}else{
			//将登录用户的相关信息保存于webUser;
			webUser.setUserId(user.getUserId());
			webUser.setRealName(user.getRealName());
			webUser.setMobile(user.getMobile());
			webUser.setUserName(user.getUserName());
			webUser.setIp(getIp(request));
			webUser.setBrowser(getBrowser(request));
			webUser.setLogintype(logintype);
			webUser.setLoginlogs(userLogin==null?null:userLogin);
			webUser.setSystemId(Constants.RS_SYSTEM.AGENT);
			webUser.setAgentId(list.get(0).getAgentId());
			webUser.setAgentName(list.get(0).getAgentName());
		webUser.setAgentMobile(list.get(0).getAgentMobile());
		}
	//保存于session
	this.request.getSession().setAttribute(WebUser.SESSION_KEY, webUser);

		//查找用户的菜单
		List<RsAuth> menus = null;
		if (this.loginService.isAdmin(this.getSessionUser().getUserId())) {//超级管理员
//			menus = this.loginService.getRsAuthList("selectAllMenu");//所有菜单
			menus = this.coreAuthService.getAllMenus(Constants.RS_SYSTEM.AGENT);//用户可以看到的所有菜单
		} else {
			menus = this.coreAuthService.getMenus(Constants.RS_SYSTEM.AGENT, user.getUserId());//用户可以看到的所有菜单
//			menus = this.loginService.getRsAuthList("selectMenu");//
		}
		webUser.setMenus(menus);
		
		JSONArray jsonArray = new JSONArray();
		
		HashMap<String, Object> hashMap=new HashMap<String, Object>();
		
		for(int i=0;i<menus.size();i++){
			
		
			hashMap.put(RsAuth.COL_AUTH_NAME, menus.get(i).getAuthName());
			
			hashMap.put(RsAuth.COL_PARENT_ID, menus.get(i).getParentId());
			
			hashMap.put(RsAuth.COL_AUTH_ID, menus.get(i).getAuthId());
			
			hashMap.put(RsAuth.COL_URL, menus.get(i).getUrl());
			
			jsonArray.add(hashMap);
			
		}
		
		
		jsonObject.put(ErrorMsg.KEY_CODE, ErrorMsg.CALL_OK);
		
		jsonObject.put(ErrorMsg.KEY_MESSAGE,"调用成功");
		
		jsonObject.put("menusData", jsonArray);
		
		return this.writeJson(jsonObject);
		/*WebUser webUser = new WebUser();
		//查找用户
		formMap.put(RsUser.COL_USER_NAME, agentName);
		SqlUtis.prepareSql(formMap
				, SqlUtis.getSQL(formMap,"a."+RsUser.COL_USER_NAME,Types.VARCHAR,SqlUtis.EQ)
				);
		RsUser user = this.userService.one(this.formMap);
		if (user==null) {//手机号码
			formMap.put(RsUser.COL_MOBILE, agentName);
			SqlUtis.prepareSql(formMap
					, SqlUtis.getSQL(formMap,"a."+RsUser.COL_MOBILE,Types.VARCHAR,SqlUtis.EQ)
					);
			user = this.userService.one(this.formMap);
		}
		if(user==null){
			this.saveActionError("用户名或密码不正确");
			return "/login.jsp";
		}
		//检查密码
		if(!agentPassword.equals(user.getPassword())){
			this.saveActionError("用户名或密码不正确");
			return "/login.jsp";
		}
		Map map = new HashMap();
		map.put("userName", agentName);
		map.put("userId", user.getUserId());
		UserLogin userLogin = this.loginService.one("ACTION_RS_USER_LOGIN.queryagentlogin",map);
		//TODO 检查是否有代理商用户
		List<Agent> list = this.userService.list("ACTION_RS_USER_LOGIN.agentlist", map);
		if(list==null || list.isEmpty()){
			this.saveActionError("没有任何用户信息");
			return "/login.jsp";
		}else{
			//将登录用户的相关信息保存于webUser;
			webUser.setUserId(user.getUserId());
			webUser.setRealName(user.getRealName());
			webUser.setMobile(user.getMobile());
			webUser.setUserName(user.getUserName());
			webUser.setIp(getIp(request));
			webUser.setBrowser(getBrowser(request));
			webUser.setLogintype(logintype);
			webUser.setLoginlogs(userLogin==null?null:userLogin);
			webUser.setSystemId(Constants.RS_SYSTEM.AGENT);
			webUser.setAgentId(list.get(0).getAgentId());
			webUser.setAgentName(list.get(0).getAgentName());
			webUser.setAgentMobile(list.get(0).getAgentMobile());
		}
		//保存于session
		this.request.getSession().setAttribute(WebUser.SESSION_KEY, webUser);

		//查找用户的菜单
		List<RsAuth> menus = null;
		if (this.coreAuthService.isAdmin(this.getSessionUser().getUserId())) {//超级管理员
			
		} else {
			menus = this.coreAuthService.list(this.coreAuthService.getStatementName("selectMenu"),null);//用户可以看到的所有菜单
		}
//		menus = this.coreAuthService.list(this.coreAuthService.getStatementName("selectAllMenu"),null);//所有菜单
		webUser.setMenus(menus);

		return "!/agent/main.jsp";*/
	}

	/**
	 * 退出系统
	 * @return
	 */
	public String loginOut(){
		request.getSession().removeAttribute(WebUser.SESSION_KEY);
		request.getSession().invalidate();
		return "!/";	
	}

	/**
	 * 验证登录是否超时
	 */
	public String isLoginTimeOut(){
		
		JSONObject jsonObject=new JSONObject();
		System.out.println("验证登录是否超时");
		try{
			
			if(!isLoginWeb()){
				
				jsonObject.put(ErrorMsg.KEY_CODE, ErrorMsg.CALL_FAIL);
				
				jsonObject.put(ErrorMsg.KEY_MESSAGE,"登录超时");
				
			}else{
				
				jsonObject.put(ErrorMsg.KEY_CODE, ErrorMsg.CALL_OK);
				
				jsonObject.put(ErrorMsg.KEY_MESSAGE,"有效");
			}
	
				
		}catch(Exception e){
			
			e.printStackTrace();
			jsonObject.put(ErrorMsg.KEY_CODE, ErrorMsg.CALL_FAIL);
			jsonObject.put(ErrorMsg.KEY_MESSAGE,"登录超时");
		}
		
		return this.writeJson(jsonObject);
		
	}
	
	
	public static String getIp(HttpServletRequest request){
		String ip = request.getHeader("x-forwarded-for");  
		if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
			ip = request.getHeader("Proxy-Client-IP");  
		}  
		if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
			ip = request.getHeader("WL-Proxy-Client-IP");  
		}  
		if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
			ip = request.getRemoteAddr();  
		}  
		return ip;
	}
	public static String getBrowser(HttpServletRequest request){
		String agent = request.getHeader("USER-AGENT");//
		String userbrowser ="";
		StringTokenizer st = null;
		//IE
		if (null != agent && -1 != agent.indexOf("MSIE")){
			st = new StringTokenizer(agent,";");
			st.nextToken();
			userbrowser += st.nextToken();
		}else{
			//谷歌Chrome
			if (null != agent && -1 != agent.indexOf("Chrome"))
				userbrowser = "Chrome";
			//苹果Safari
			else if(null != agent && -1 != agent.indexOf("Safari"))
				userbrowser = "Safari";
			//火狐Firefox
			else if(null != agent && -1 != agent.indexOf("Firefox"))
				userbrowser = "Firefox";
			//Opera
			else if(null != agent && -1 != agent.indexOf("Opera"))
				userbrowser = "Opera";
			else{
				userbrowser ="unknow";
			}
		}
		return userbrowser.trim();
	}
	
	/**
	 * 查询用户菜单
	 * @return
	 */
	public String queryUserMenus(){
		
		JSONObject jsonObject=new JSONObject();
		
		try {
			String userId = this.getSessionUser().getUserId();
			//查找用户的菜单
			List<RsAuth> menus = null;
			if (this.coreAuthService.isAdmin(this.getSessionUser().getUserId())) {//超级管理员
				menus = this.coreAuthService.getAllMenus(Constants.RS_SYSTEM.AGENT);//所有菜单
			} else {
				menus = this.coreAuthService.getMenus(Constants.RS_SYSTEM.AGENT, userId);//用户可以看到的所有菜单
			}
			JSONArray jsonArray = new JSONArray();
			HashMap<String, Object> hashMap;
			for(int i=0;i<menus.size();i++){
				hashMap=new HashMap<String, Object>();
				
				hashMap.put(RsAuth.COL_AUTH_NAME, menus.get(i).getAuthName());
				
				hashMap.put(RsAuth.COL_PARENT_ID, menus.get(i).getParentId()==null?"":menus.get(i).getParentId());
				
				hashMap.put(RsAuth.COL_AUTH_ID, menus.get(i).getAuthId());
				
				hashMap.put(RsAuth.COL_URL, menus.get(i).getUrl());
				
				hashMap.put(RsAuth.COL_MEMO, menus.get(i).getMemo());
				
				jsonArray.add(hashMap);
				
			}
					
			jsonObject.put(ErrorMsg.KEY_CODE, ErrorMsg.CALL_OK);
			
			jsonObject.put(ErrorMsg.KEY_MESSAGE,"调用成功");
			
			jsonObject.put("menusData", jsonArray);
			
		} catch (Exception e) {
			e.printStackTrace();
			jsonObject.put(ErrorMsg.KEY_CODE, ErrorMsg.CALL_FAIL);
			jsonObject.put(ErrorMsg.KEY_MESSAGE,"调用失败");
		}
		return this.writeJson(jsonObject);
	}
    /**
     * 在首頁顯示的圖標的權限
     * @return
     */
	public String queryShowOperate(){
	    JSONObject jsonObject = new JSONObject();
		try{
			boolean AGENT_MY_ACCOUNT_JOURNAL_MANAGER=this.coreAuthService.checkRigth(this.getSessionUser().getUserId(), "AGENT_MY_ACCOUNT_JOURNAL_MANAGER"); //帳戶流水
			boolean AGENT_MY_ACCOUNT_SETTLE_MANAGER=this.coreAuthService.checkRigth(this.getSessionUser().getUserId(), "AGENT_MY_ACCOUNT_SETTLE_MANAGER"); //提現
			boolean AGENT_MY_ACCOUNT_SETTLE_HIS_MANAGER=this.coreAuthService.checkRigth(this.getSessionUser().getUserId(), "AGENT_MY_ACCOUNT_SETTLE_HIS_MANAGER"); //提現記錄
			boolean AGENT_MY_INFO_MANAGER=this.coreAuthService.checkRigth(this.getSessionUser().getUserId(), "AGENT_MY_INFO_MANAGER"); //基本信息
			boolean AGENT_MY_BANK_MANAGER=this.coreAuthService.checkRigth(this.getSessionUser().getUserId(), "AGENT_MY_BANK_MANAGER"); //銀行帳戶
			boolean AGENT_MY_SECURITY_MANAGER=this.coreAuthService.checkRigth(this.getSessionUser().getUserId(), "AGENT_MY_SECURITY_MANAGER"); //安全設置
			boolean AGENT_SHOP_MANAGER=this.coreAuthService.checkRigth(this.getSessionUser().getUserId(), "AGENT_SHOP_MANAGER"); //商家查詢
			boolean AGENT_TERNIMAL_USER_MANAGER=this.coreAuthService.checkRigth(this.getSessionUser().getUserId(), "AGENT_TERNIMAL_USER_MANAGER"); //操作員查詢
			boolean AGENT_TERNIMAL_MONITOR_MANAGER=this.coreAuthService.checkRigth(this.getSessionUser().getUserId(), "AGENT_TERNIMAL_MONITOR_MANAGER"); //終端監控

			jsonObject.put("AGENT_MY_ACCOUNT_JOURNAL_MANAGER", AGENT_MY_ACCOUNT_JOURNAL_MANAGER);
			jsonObject.put("AGENT_MY_ACCOUNT_SETTLE_MANAGER", AGENT_MY_ACCOUNT_SETTLE_MANAGER);
			jsonObject.put("AGENT_MY_ACCOUNT_SETTLE_HIS_MANAGER", AGENT_MY_ACCOUNT_SETTLE_HIS_MANAGER);
			jsonObject.put("AGENT_MY_INFO_MANAGER", AGENT_MY_INFO_MANAGER);
			jsonObject.put("AGENT_MY_BANK_MANAGER", AGENT_MY_BANK_MANAGER);
			jsonObject.put("AGENT_MY_SECURITY_MANAGER", AGENT_MY_SECURITY_MANAGER);
			jsonObject.put("AGENT_SHOP_MANAGER",AGENT_SHOP_MANAGER);
			jsonObject.put("AGENT_TERNIMAL_USER_MANAGER", AGENT_TERNIMAL_USER_MANAGER);
			jsonObject.put("AGENT_TERNIMAL_MONITOR_MANAGER", AGENT_TERNIMAL_MONITOR_MANAGER);
			jsonObject.put(ErrorMsg.KEY_CODE, ErrorMsg.CALL_OK);
			jsonObject.put(ErrorMsg.KEY_MESSAGE,"调用成功");
		}catch(BusinessException e){
   	       		jsonObject.put(ErrorMsg.KEY_CODE, ErrorMsg.CALL_FAIL);
   	       		jsonObject.put(ErrorMsg.KEY_MESSAGE, e.getMessage());
		}catch(Exception e){
	       		jsonObject.put(ErrorMsg.KEY_CODE, ErrorMsg.CALL_FAIL);
	       		jsonObject.put(ErrorMsg.KEY_MESSAGE, e.getMessage());
		}
  		return this.writeJson(jsonObject);
	}
	/**
	 * 获取代理商的下级代理商以及商家
	 * @return
	 */
	public String getAgentTree(){
		
	    logger.info("****************LoginAction getAgentTree begin***************");
		JSONObject jsonObject = null;
		JSONArray jsonArray = null;
		try{
			//代理商代码或商家代码
			String id = this.request.getParameter("id");
			//1：商家类型，2代理商类型
			String type = this.request.getParameter("type");
			logger.info("前端传递的参数：id = " + id +"&type = " + type);
			
//			if("1".equals(type)){
//				return this.getTerminalByShopId(id); //商家查看终端
//			}
			
			if(id == null || "".equals(id)){
			   id = this.getSessionUser().getAgentId();
			}
			jsonObject  = new JSONObject();
			List<ErpShop> shopList =  webAgentService.getShopListByAgentId(id);
			List<RsAgent> agentList = webAgentService.getAgentListByParentId(id);
//			List<RsAgentTerminal> rsAgentTerminals = webAgentService.getTerminalByAgent(id);
		    jsonArray = new JSONArray();
		    Map map;
		    for(ErpShop shop : shopList){
		    	map = new HashMap();
		    	String tempShopId = shop.getShopId();
		    	map.put("shopName", shop.getShopName());
//		    	map.put("terminalChildNum",webAgentService.getChildTerminalByShopId(tempShopId));
		    	map.put("shopId", shop.getShopId());
		    	ShopMemberConcern shopMemberConcern = this.webAgentService.getShopMemberConcern(tempShopId);
		    	map.put("memberNum", shopMemberConcern.getMemberNum());
		    	map.put("concernNum", shopMemberConcern.getConcernNum());
			    jsonArray.add(map);
			}
			jsonObject.put("shopList",jsonArray);
			jsonArray = new JSONArray();
			String tempAgentId = null;
			for(RsAgent rsAgent : agentList){
				map = new HashMap();
				tempAgentId = rsAgent.getAgentId();
				map.put("agentName",rsAgent.getAgentName());
				map.put("agentChildNum",webAgentService.getChildAgentByParentId(tempAgentId));
				map.put("agentId", tempAgentId);
				map.put("shopNum",this.webAgentService.getChildShopByAgentId(tempAgentId));
				jsonArray.add(map);
			}
			jsonObject.put("agentList",jsonArray);
//			jsonArray = new JSONArray();
//			for(RsAgentTerminal rsAgentTerminal : rsAgentTerminals){
//				map = new HashMap();
//				map.put("terminalId",  rsAgentTerminal.getTerminalId());
//				jsonArray.add(map);
//			}
//			jsonObject.put("agentTerminalList",jsonArray);
			jsonObject.put("code","1");
			jsonObject.put("message","调用成功");
			jsonObject.put("type", "-1");
			
		}catch(BusinessException e){
			e.printStackTrace();
			jsonObject = JSONObject.fromObject(e.getErrorMsg());
		}
		catch(Exception e){
			e.printStackTrace();
			jsonObject = JSONObject.fromObject(new ErrorMsg(e.getMessage()));
			jsonObject.put(ErrorMsg.KEY_CODE,"-1");
			jsonObject.put(ErrorMsg.KEY_MESSAGE, e.getMessage());
		}
		
//		System.out.println("jsonObject = " + jsonObject);
		logger.info("****************LoginAction getAgentTree end***************");
		return this.writeJson(jsonObject);
	}
	
//	/**
//	 * 根据商家代码查找终端
//	 * @return
//	 */
//	public String getTerminalByShopId(String shopId){
//		JSONObject jsonObject = new JSONObject();
//		try{
//			String tempShopId = shopId;//this.request.getParameter("shopId");
////			System.out.println("tempShopId = " + tempShopId.substring(4));
//			if(tempShopId != null && !"".equals(tempShopId)){
//				List<RsTerminal> terminalList = this.webAgentService.getTerminalListByShopId(tempShopId); //向数据库发送请求
//			    JSONArray jsonArray = new JSONArray();
//				for(RsTerminal terminal : terminalList){
//			    	Map hash = new HashMap();
//			    	hash.put("terminalId", terminal.getTerminalId());
//			    	jsonArray.add(hash);
//			    }
//				jsonObject.put("terminalList",jsonArray);
//				jsonObject.put(ErrorMsg.KEY_CODE,"1");
//				jsonObject.put(ErrorMsg.KEY_MESSAGE, "调用成功");
//				jsonObject.put("type", "3");
//			}
//		}catch(BusinessException e){
//			jsonObject = JSONObject.fromObject(e.getErrorMsg());
//		}catch(Exception e){
//			jsonObject.put(ErrorMsg.KEY_CODE,"-1");
//			jsonObject.put(ErrorMsg.KEY_MESSAGE, e.getMessage());
//		}
//		return this.writeJson(jsonObject);
//	 }
   }
